// const path=require('path');
var now = new Date();  
          
        var year = now.getFullYear();       //年  
        var month = now.getMonth() + 1;     //月  
        var day = now.getDate();            //日  
        if (month < 10) {
		    month = "0" + month;
		}
		if (day < 10) {
		    day = "0" + day;
		}
   		var mytime = year.toString() + month.toString() + day.toString();
   		// console.log(mytime);

// 获取图片
exports.getImage = function(req,res){
	// var aaaa = path.relative('F:\\project\\安检机容器\\代码\\SecurityCheck\\starter-node-angular\\public\\assets\\img\\IMG_0079.JPG', 'F:\\biyeji\\IMG_0079.JPG');
	// console.log(aaaa);
    req.getConnection(function(err,conn){
		if(err){
			console.log("Failed to connect");
			res.status(500).json(err);
		};
   		
   		
   		var sql = "SELECT * FROM " + mytime;
   		// console.log(sql);
		var query = conn.query("SELECT * FROM image_actual",function(err,rows){
			if(err){
				console.log(err);
			}else{

				res.status(200).json({"image":rows});
			}
		});
	})

};


//更新漏报类型
exports.misimgData = function(req,res){
	var misImg = req.body;
	console.log(misImg);
	var misImg_goods="";
	for(var i = 0;i < misImg.subdata.length-1;i++){
		misImg_goods += misImg.subdata[i] + ",";
	}
	misImg_goods += misImg.subdata[misImg.subdata.length-1];
	req.getConnection(function(err,conn){
		if(err){
			console.log("Failed to connect");
			res.status(500).json(err);
		};
		// var sql = 'UPDATE `123` SET levout=1,goods=' + '\'' + misImg_goods + '\'' + 'WHERE url=' + '\'' + misImg.imgurl + '\'' + ';';
		var sql = "UPDATE `"+ mytime + "` SET levout=1,goods='" + misImg_goods + "' WHERE url='" + misImg.imgurl + "';";
		console.log(sql);
		//拼接sql
		var query = conn.query(sql,function(err,rows){
			if(err){
				console.log(err);
			}
			else{
				console.log("更新成功！");
				res.status(200).json("success");//数据库有数据
			}
		});
	})
};


//更新误报类型
exports.falseimgData = function(req,res){
	var falseImg = req.body;
	console.log(falseImg);
	var falseImg_goods="";
	for (var i = 0; i < falseImg.subdata.length-1; i++) {
		falseImg_goods += falseImg.subdata[i] + ",";
	}
	falseImg_goods += falseImg.subdata[falseImg.subdata.length-1];
	console.log(falseImg_goods);
	
	// console.log("12345");
	req.getConnection(function(err,conn){
		if(err){
			console.log("Failed to connect");
			res.status(500).json(err);
		};
		// console.log("6789");
		// var querystring = '';
		// var sql = 'UPDATE 123 SET misinfo=' + '\''+'1'+ '\''+ ',goods=' + '\'' + falseImg_goods + '\'' + 'WHERE url=' + '\'' + falseImg.imgurl + '\'' + ';';
		// var sql = 'UPDATE `123` SET msinfo=1,goods=' + '\'' + falseImg_goods + '\'' + 'WHERE url=' + '\'' + falseImg.imgurl + '\'' + ';';
		var sql = "UPDATE `"+ mytime + "` SET msinfo=1,goods='" + falseImg_goods + "' WHERE url='" + falseImg.imgurl + "';";
		console.log(sql);
		//拼接sql
		var query = conn.query(sql,function(err,rows){
			if(err){
				console.log(err);
				// res.status(200).json({"user_data":""});//数据库无数据
			}else{
				console.log("更新成功！");
				res.status(200).json("success");//数据库有数据
				
			}
		});
	})

};


